package com.config;

import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * jks配置文件类
 *
 * @author zyf
 */
public class JksConfiguration extends RCjavaConfiguration {

    private String jksPath = "";
    private String jksName = "";
    private String jksAlias = "";
    private String jksPasswd = "";
    private PropertiesConfiguration jksConfig = new PropertiesConfiguration();

    // 默认是用的是rcjava.properties加载的
    public JksConfiguration() {
        super();
        load();
    }

    /**
     * 自定义之后，重新加载JKSConfig
     *
     * 自定义如下：
     * JksConfiguration jksConfig = new JksConfiguration();
     * jksConfig.setRcJavaPropsFile(new File("custom path")); // 自定义的customPath
     * jksConfig.load();
     */
    public void loadJksConfig() {
        load();
    }

    /**
     * 从rcJavaConfig中获取相关的jks配置项
     */
    private void load() {

        // 加载RcJavaConfig
        // loadRcJavaConfig();

        this.jksPath = rcJavaConfig.getString("jks.path");
        this.jksName = rcJavaConfig.getString("jks.name");
        this.jksAlias = rcJavaConfig.getString("jks.alias");
        this.jksPasswd = rcJavaConfig.getString("jks.password");

        jksConfig.setProperty("path", jksPath);
        jksConfig.setProperty("name", jksName);
        jksConfig.setProperty("alias", jksAlias);
        jksConfig.setProperty("password", jksPasswd);

        logger.info("jks，path：{}， name：{}， alias：{}，password：{}", jksPath, jksName, jksAlias, jksPasswd);

    }

    public String getJksPath() {
        return jksPath;
    }

    public String getJksName() {
        return jksName;
    }

    public String getJksAlias() {
        return jksAlias;
    }

    public String getJksPasswd() {
        return jksPasswd;
    }

    /**
     * Properties Contain keys: "path","name","alias","password"
     *
     * @return
     */
    public PropertiesConfiguration getJksConfig() {
        return jksConfig;
    }

}
